package com.example.bobo.yuejian322.Fragment.zhuyeFragment;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.bobo.yuejian322.Adapter.ZhuyeMasterAdapter;
import com.example.bobo.yuejian322.Adapter.ZhuyePlayAdapter;
import com.example.bobo.yuejian322.Interfa.ZhuyePlaySeverice;
import com.example.bobo.yuejian322.R;
import com.example.bobo.yuejian322.base.BaseFragment;
import com.example.bobo.yuejian322.bean.Contest;
import com.example.bobo.yuejian322.bean.Master;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * A simple {@link Fragment} subclass.
 */
public class PlayFragment extends BaseFragment {
    private RecyclerView recyclerView;
    private ZhuyePlayAdapter adapter;
    private  String contest;
    public PlayFragment() {
        // Required empty public constructor
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        recyclerView = (RecyclerView) view.findViewById(R.id.recyclerView_play);
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl("http://172.24.10.175/workout/api.php/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        ZhuyePlaySeverice zhuyePlaySeverice =retrofit.create(ZhuyePlaySeverice.class);
        Call<List<Contest>> listCall =zhuyePlaySeverice.ContestList(getUserId(),1,contest);

        listCall.enqueue(new Callback<List<Contest>>() {
            @Override
            public void onResponse(Call<List<Contest>> call, Response<List<Contest>> response) {
                List<Contest> contestList = response.body();
                if (getActivity() != null) {
                    adapter = new ZhuyePlayAdapter(getActivity(), contestList);
                    LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
                    layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
                    recyclerView.setLayoutManager(layoutManager);
                    recyclerView.setAdapter(adapter);
                    recyclerView.setItemAnimator(new DefaultItemAnimator());
                }
            }
            @Override
            public void onFailure(Call<List<Contest>> call, Throwable t) {
            }
        });
    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_play, container, false);
    }

}
